﻿using System;
using NetworkLib.Utilities;
using PBO.Network;
using PBO.Network.Enumerations;
using PBO.Network.Domain;

namespace PokemonBattle.BattleRoom.Client
{
    /// <summary>
    /// 对战请求信息
    /// </summary>
    public class ChallengeInfo : DataByteArray
    {
        /// <summary>
        /// 对战模式
        /// </summary>
        public BattleMode BattleMode { get; set; }

        /// <summary>
        /// 连接模式
        /// </summary>
        public BattleLinkMode LinkMode { get; set; }

        /// <summary>
        /// 可选规则
        /// </summary>
        public BattleRule[] Rules { get; set; }

        #region abstract

        public override void Read(ByteArray byteArray)
        {
            BattleMode = (BattleMode)byteArray.ReadInt();
            LinkMode = BattleLinkModeHelper.Parse(byteArray.ReadInt());
            this.Rules = DataByteArray.ReadArray<BattleRule>(byteArray, b => (BattleRule)b.ReadInt());
        }

        public override void Write(ByteArray byteArray)
        {
            byteArray.WriteInt((int)this.BattleMode);
            byteArray.WriteInt((int)this.LinkMode);
            DataByteArray.WriteArray<BattleRule>(this.Rules, byteArray, (b, t) => b.WriteInt((int)t));
        }

        #endregion

    }
}